package com.kurumi.autoprint.util;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

public class ObjectUtil {


	 /**
    * 获取利用反射获取类里面的值和名称
    *
    * @param obj
    * @return
    * @throws IllegalAccessException
    */
   public static Map<String, Object> objectToMap(Object obj) throws IllegalAccessException {
       Map<String, Object> map = new HashMap<>();
       Class<?> clazz = obj.getClass();
       System.out.println(clazz);
       for (Field field : clazz.getDeclaredFields()) {
           field.setAccessible(true);
           String fieldName = field.getName();
           Object value = field.get(obj);
           map.put(fieldName, value);
       }
       return map;
   }
   
   
   public static void main(String[] args) throws IllegalAccessException {
	Map<String,Object> map = new HashMap<>();
	map.put("resultCode", 1);
	map.put("resultSuccess","success");
	Object obj = map;
	System.out.println(objectToMap(obj));
	
}
}
